<include file="Common:minheader" />
<!-- /. NAV SIDE  -->
<style>
	.imgcss img{
		width:150px;
	}
</style>
<form class="layui-form" action="">
    <input type="hidden" name="id" value="{$info.id}">
	<div class="layui-form-item">
		<label class="layui-form-label">名称</label>
		<div class="layui-input-block">
		  <input value="{$info.brand_name}" type="text" name="brand_name" required  lay-verify="required" placeholder="请输入分类名称" autocomplete="off" class="layui-input">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">图片</label>
		<div class="layui-input-block">
			<div class="layui-upload">
			  <button type="button" class="layui-btn" id="test1">上传图片</button>
			  <div class="layui-upload-list" id="demo1" data-id="">
				<if condition="!empty($info['brand_small_pic'])">
					<div class="imgcss"><input type="hidden" name="brand_small_pic" id="smallimage" value="{$info.brand_small_pic}"><a href="{$info.brand_small_pic}" target="_blank"><img src="{$info.brand_small_pic}" class="layui-upload-img"></a></div>
				</if>
			  </div>
			  <div id="demoText"></div>
			</div> 
		</div>
	</div>
	<!-- <div class="layui-form-item">
		<label class="layui-form-label">点击图片</label>
		<div class="layui-input-block">
			<div class="layui-upload">
			  <button type="button" class="layui-btn" id="test2">上传图片</button>
			  <div class="layui-upload-list" id="demo2" data-id="">
				<if condition="!empty($info['cate_small_pic2'])">
					<div class="imgcss"><input type="hidden" name="cate_small_pic2" id="smallimage2" value="{$info.cate_small_pic2}"><a href="{$info.cate_small_pic2}" target="_blank"><img src="{$info.cate_small_pic2}" class="layui-upload-img"></a></div>
				</if>
			  </div>
			  <div id="demoText2"></div>
			</div> 
		</div>
	</div> -->
	<div class="layui-form-item">
		<label class="layui-form-label">排序</label>
		<div class="layui-input-block">
		  <input value="{$info.sort}" type="text" name="sort" required  lay-verify="required" placeholder="数字越大,排序越前面" autocomplete="off" class="layui-input">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">是否启用</label>
		<div class="layui-input-block">
		  <input type="radio" name="status" value="1" title="是" <if condition="$info.status eq 1">checked</if>>
		  <input type="radio" name="status" value="0" title="否" <if condition="$info.status eq 0">checked</if>>
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-input-block">
		  <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
		  <button type="reset" class="layui-btn layui-btn-primary">重置</button>
		</div>
  </div>
</form>
<script>
	//Demo
	layui.use('upload', function(){
		var $ = layui.jquery
		,upload = layui.upload;
		var uploadInst = upload.render({
			elem: '#test1'
			,url: "{:U('Common/uploadImage')}"
			,size:'1048576'
			,multiple: false
			,method: 'POST'
			,before: function(obj){
				//预读本地文件示例，不支持ie8
				obj.preview(function(index, file, result){
					$('#demo1').html('<div class="imgcss"><input type="hidden" name="cate_small_pic" id="smallimage" value=""><img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img"></div>'); //图片链接（base64）
				});
			}
			,done: function(res){
				//如果上传失败
				if(res.code==0){
					return layer.msg(res.value);
				}else{
					$('#smallimage').val(res.value);
				}
			}
			,error: function(){
				//演示失败状态，并实现重传
				var demoText = $('#demoText');
				demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
				demoText.find('.demo-reload').on('click', function(){
					uploadInst.upload();
				});
			}
		});
		var uploadInst2 = upload.render({
			elem: '#test2'
			,url: "{:U('Common/uploadImage')}"
			,size:'1048576'
			,multiple: false
			,method: 'POST'
			,before: function(obj){
				//预读本地文件示例，不支持ie8
				obj.preview(function(index, file, result){
					$('#demo2').html('<div class="imgcss"><input type="hidden" name="cate_small_pic2" id="smallimage2" value=""><img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img"></div>'); //图片链接（base64）
				});
			}
			,done: function(res){
				//如果上传失败
				if(res.code==0){
					return layer.msg(res.value);
				}else{
					$('#smallimage2').val(res.value);
				}
			}
			,error: function(){
				//演示失败状态，并实现重传
				var demoText = $('#demoText2');
				demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
				demoText.find('.demo-reload').on('click', function(){
					uploadInst2.upload();
				});
			}
		});
	});
	layui.use('form', function(){
	  var form = layui.form;
	  //监听提交
	  form.on('submit(formDemo)', function(data){
			var cont = data.field;
			$.ajax({
				url:"{:U('Goods/editGoodsBrand')}",
				type:'post',
				dataType:'json',
				data:cont,
				success:function(data){
					if(data.code==0){
						layer.alert(data.message);
					}else{
						layer.alert(data.message, function(index){
							//do something
							window.parent.location.reload();
							var index = parent.layer.getFrameIndex(window.name); 
							parent.layer.close(index);
						});
					}
				}
			});
			//layer.msg(JSON.stringify(data.field));
			return false;
	  });
	});
</script>
<!-- /. PAGE INNER  -->
<include file="Common:footer" />